// LinkList.h
#pragma once

namespace ANvDbg
{
    class LinkList
    {
    public:
        LinkList() : m_next(nullptr)
        {

        }

    public:
        template<class T>
        T* GetNext()
        {
            return (T*)m_next;
        }

        void PushList(LinkList* node)
        {
            if (m_next == nullptr)
            {
                m_next = node;
            }
            else
            {
                GetNext<LinkList>()->PushList(node);
            }
        }

    public:
        void* m_next;
    };

    class DoubleLinkedList
    {
    public:
        DoubleLinkedList() : m_next(nullptr), m_prev(nullptr)
        {

        }

    public:
        template<class T>
        T* GetNext()
        {
            return (T*)m_next;
        }

        template<class T>
        T* GetPrev()
        {
            return (T*)m_prev;
        }

        void PushList(DoubleLinkedList* node)
        {
            if (m_next == nullptr)
            {
                m_next = node;
                node->m_prev = this;
            }
            else
            {
                GetNext<DoubleLinkedList>()->PushList(node);
            }
        }

        void InsertBefore(DoubleLinkedList* node)
        {

        }

        void InsertAfter(DoubleLinkedList* node)
        {

        }

        void PopList()
        {
            if (m_next != nullptr)
            {
                GetNext<DoubleLinkedList>()->m_prev = m_prev;
                m_next = nullptr;
            }

            if (m_prev != nullptr)
            {
                GetPrev<DoubleLinkedList>()->m_next = m_next;
                m_prev = nullptr;
            }
        }

    public:
        void* m_next;
        void* m_prev;
    };
}